package com.controller;

import com.entity.FriendType;
import com.service.FriendTypeService;
import com.vo.ResponseVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api")
public class FriendTypeController {
    @Autowired
    private FriendTypeService friendTypeService;

    @GetMapping("/friendType")
    public ResponseVO getByUserId(Integer userId){
        List<FriendType> result = friendTypeService.getByUserId(userId);
        return  new ResponseVO("200",null,result);
    }

    /**
     * 添加分组
     *
     * @param typeName 分组名
     * @param userId   用户ID
     * @return
     */
    @PostMapping("/friendType/add")
    public ResponseVO addFriendType(String typeName, Integer userId) {
        return new ResponseVO("200", null, friendTypeService.addFriendType(typeName, userId));
    }

    /**
     * 修改分组名
     * @param typeName 分组名
     * @param typeId   分组ID
     * @return
     */
    @PostMapping("/friendType/edit")
    public ResponseVO editFriendType(String typeName, Integer typeId) {
        return new ResponseVO("200", null, friendTypeService.editFriendType(typeName, typeId));
    }

    /**
     * 删除分组
     *
     * @param typeId 分组ID
     * @return
     */
    @PostMapping("/friendType/del")
    public ResponseVO delFriendType(Integer typeId) {
        return new ResponseVO("200", null, friendTypeService.delFriendType(typeId));
    }
}
